﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using NHibernate;
using NHibernate.Criterion;

namespace SmartProject.Entity
{
    public class Permission : EntityBase
    {
        public virtual string Action { get; set; }

        /// <summary>
        /// Gets the Permission instance by instance and the group name that is is under.
        /// </summary>
        /// <param name="groupName">Name of the grouping for this permission.</param>
        /// <param name="action"></param>
        /// <returns></returns>
        public static Permission GetPermission(ISession session, string action)
        {
            IList<ICriterion> expressions = new List<ICriterion>();
            expressions.Add(Restrictions.Eq("Action", action));
            IList<EntityBase> entities = Find(session, expressions, null, typeof(Permission));
            if (entities != null && entities.Count == 1)
            {
                return (Permission)entities[0];
            }
            return null;
        }
    }
}
